(function () {
    'use strict';
    angular.module('KingAdmin.pages.sys.job')
        .controller('JobCtrl', JobCtrl);

    /** @ngInject */
    function JobCtrl($scope, $stateParams, $state,$uibModalInstance, JobService, DictService) {
        var kt = this;
        kt.job = {};
        kt.title = '编辑定时任务';

        if($stateParams.id){
            if ($stateParams.isView) {
                kt.isView = true;
                kt.title = '查看定时任务';
            }

            JobService.getInfo({id:$stateParams.id},
                function (data) {

                kt.job = data;
                kt.job.pause = kt.job.pause.toString();
                kt.job.enable = kt.job.enable.toString();

                console.log(kt.job);
            })
        }else{
            kt.isAdd = true;
            kt.title = '添加定时任务';
            kt.job = {
                cronExpression: "*/30 * * * * ?",
            };
        }

        kt.enableDict = [];
        DictService.getList('JOB_ENABLE_DICT',function (data) {
            kt.enableDict = data.result;
            kt.isShowEnable = true;
            // $scope.$digest();
        });

        kt.pauseDict = [];
        DictService.getList('JOB_PAUSE_DICT',function (data) {
            kt.pauseDict = data.result;
            kt.isShowPause = true;
            // $scope.$digest();
        });


        kt.save = function () {
            JobService.save(kt.job,function (data) {
                $uibModalInstance.close(true);
            });
        };

        $uibModalInstance.rendered.then(function() {

        });
    }

})();
